package com.bjdd.jdy.base;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;

import com.bjdd.jdy.App;
import com.bjdd.jdy.R;
import com.bjdd.jdy.util.Api;
import com.bjdd.jdy.util.DialogUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.view.other.CustomDialog;
import com.bjdd.jdy.view.widget.LoadingDialog;

import java.util.Map;


/**
 * Created by hp on 2016/8/13.
 */
public abstract class BasePresenter<M,V> {

    public Context context;
    public M model;
    public V view;
    public RxManager rxManager = new RxManager();
    public Map<String,String> params = Api.getInstance().getBaseParams();

    protected DialogUtil mDialogUtil;
    protected Dialog mDialog;
    protected ProgressDialog progressDialog;
    protected LoadingDialog dialog;

    public void setVM(Context context,V v, M m){
        this.context = context;
        mDialogUtil = new DialogUtil(context);
        this.view = v;
        this.model = m;
        this.onStart();
    }

    protected void showLoadingDialog(Boolean isCanClose) {

       /* progressDialog = new ProgressDialog(App.getCurrentActivity(),
                R.style.dialogBase);
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage("加载中...");
        progressDialog.setCancelable(isCanClose);
       // progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        progressDialog.show();*/
       if (dialog == null){
           dialog = new LoadingDialog(context,R.style.dialogBase);
           dialog.setCancelable(isCanClose);
           dialog.setTipText("加载中");
       }
       if (!dialog.isShowing()){
           dialog.show();
       }
    }

    protected void hideLoadingDialog() {
        /*if(progressDialog != null && progressDialog.isShowing()){
            progressDialog.dismiss();
        }*/
        if (dialog != null && dialog.isShowing()){
            L.d("关闭加载框");
            dialog.dismiss();
        }

    }

    public abstract void onStart();
    public void onResume(){}
    public void onDestroy(){
        rxManager.clear();
    }

}
